home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / enterctl / entedit.pas < prev    next >
Pascal/Delphi Source File  |  1995-12-22  |  2KB  |  85 lines

  1. {
  2.   Edit control that reponds as if the <Tab> key has been pressed when an
  3.   <Enter> key is pressed, moving to the next control.
  4.   Very simple extension to the KeyPress event, this technique should work
  5.   with TDBedit as well, Useful for data entry type apps.
  6.   Less trouble than using the Keypreview function of the form to do the same
  7.   thing.
  8.  
  9.   Please Use Freely.
  10.  
  11.   Simon Callcott  CIS: 100574, 1034
  12. }
  13.  
  14.  
  15. unit Entedit;
  16.  
  17. interface
  18.  
  19. uses
  20.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  21.   Forms, Dialogs, StdCtrls;
  22.  
  23. type
  24.   TEnterEdit = class(TEdit)
  25.   private
  26.  
  27.   protected
  28.  
  29.     procedure KeyPress(var Key: Char); override;
  30.     procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  31.  
  32.   public
  33.  
  34.   published
  35.  
  36.   end;
  37.  
  38. procedure Register;
  39.  
  40. implementation
  41.  
  42. procedure Register;
  43. begin
  44.   RegisterComponents('Samples', [TEnterEdit]);
  45. end;
  46.  
  47. procedure TEnterEdit.KeyPress(var Key: Char);
  48. var
  49.    MYForm: TForm;
  50. begin
  51.  
  52.    if Key = #13 then
  53.    begin
  54.        MYForm := GetParentForm( Self );
  55.        if not (MYForm = nil ) then
  56.            SendMessage(MYForm.Handle, WM_NEXTDLGCTL, 0, 0);
  57.        Key := #0;
  58.    end;
  59.  
  60.    if Key <> #0 then inherited KeyPress(Key);
  61.  
  62. end;
  63.  
  64. procedure TEnterEdit.KeyDown(var Key: Word; Shift: TShiftState);
  65. var
  66.    MYForm: TForm;
  67.    CtlDir: Word;
  68. begin
  69.  
  70.    if (Key = VK_UP) or (Key = VK_DOWN) then
  71.    begin
  72.        MYForm := GetParentForm( Self );
  73.        if Key = VK_UP then CtlDir := 1
  74.        else CtlDir :=0;
  75.        if not (MYForm = nil ) then
  76.            SendMessage(MYForm.Handle, WM_NEXTDLGCTL, CtlDir, 0);
  77.    end
  78.    else inherited KeyDown(Key, Shift);
  79.  
  80. end;
  81.  
  82.  
  83.  
  84. end.
  85.